package chapter04;

public class Test05_throw {
    public static void main(String[] args) {
        try {
            setAge(10);
        }catch (Exception e){
            System.out.println(e.getMessage());
        }
    }
    public static void setAge(int age) throws Exception{
        if(age<0){
            //使用throw关键字抛出异常
            throw new Exception("年龄必须是正整数");
        }else{
            System.out.println("年龄是："+age);
        }
    }
}
